package com.honour.busserver.backup.job;

import com.honour.busserver.backup.base.ApplicationContextUtils;
import com.honour.busserver.backup.entity.CentOSOneEntity;
import com.honour.busserver.backup.entity.SSHRegisterEntity;
import com.honour.busserver.backup.utils.SshCommanUtil;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.quartz.SchedulerException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.io.IOException;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class DmBackUpJob extends QuartzJobBean {


    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        // 执行 定时任务逻辑

        try {
            //获取执行id
            context.getScheduler().getSchedulerInstanceId();
            String dir = context.getMergedJobDataMap().get("dir").toString();
            System.out.println("执行中.......");
            /*CentOSOneEntity centOSOneEntity = (CentOSOneEntity) ApplicationContextUtils.getBean("CentOSOneEntity");
            SSHRegisterEntity sshRegisterEntity = new SSHRegisterEntity(centOSOneEntity);
            StringBuilder exec = sshRegisterEntity.exec(SshCommanUtil.dmBackUpcommands(centOSOneEntity.getDbUser(), centOSOneEntity.getDbPassword(), dir, centOSOneEntity.getBin()));
           //任务执行返回值
            String res = exec.toString();*/
            //获取执行任务名称
            context.getJobDetail().getKey().getName();
        } catch (SchedulerException e) {
            throw new RuntimeException(e);
        /*} catch (IOException e) {
            throw new RuntimeException(e);*/
        }
    }
}
